package Command;

import Server.Command;
import Server.cmdArguments;

public class DeleteCommand implements Command{
	private cmdArguments args;
	private Integer i;
	
	@Override
	public String execute() {
		String result = "";
		try {
			i = Integer.parseInt(args.commands[1].trim());
			boolean found = args.bst.delete(i); // picks the delete with Integer obj, removes the number and rebuilds the tree
			if (found) {
				result = i + " deleted.";
			} else {
				result = i + " not present.";
			}
		} catch (Exception e) {
			//e.printStackTrace();
			result = "Missing or incorrect argument";
		}
		return result;
	}

	@Override
	public String undo() {
		String result = "Undo failed.";
		if (args.bst.insert(i)) {
			result = i + " has been restored. Undo was a success!";
		}
		return result;
	}

	@Override
	public void setArgs(cmdArguments args) {
		this.args = args;
	}
	
}
